function isIE() {
    var ua = window.navigator.userAgent;
    if (ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident/") > -1) {
        return true;
    }
    return false;
}

function loadScript(src, cb) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = src;
    script.onload = cb;
    document.body.appendChild(script);
}

function loadCss(href) {
    var link = document.createElement("link");
    link.rel = "stylesheet";
    link.type = "text/css";
    link.href = href;
    document.head.appendChild(link);
}

function showTips() {
    var tips = document.createElement("div");
    tips.className = "ie-tips-dialog";
    tips.innerHTML =
        '<div class="tips-content">' +
        '<div class="tips-title">提示</div>' +
        '<div class="tips-text">' +
        "<p>由于老版IE浏览器不适合新一代网站，网站功能显示和体验不佳，为避免对您使用造成困扰，</p>" +
        "<p><b>请您安装</b>火狐/谷歌浏览器，点击图片<b>即可安装</b>，</p>" +
        "<p><b>享受更佳的浏览体验</b></p>" +
        "</div>" +
        '<div class="tips-btn">' +
        "<a class='btn-item' href='https://www.google.cn/intl/zh-CN/chrome/' target='_blank'>" +
        "<img src='https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/icon-chrome.png' />" +
        "<div class='btn-text'>谷歌浏览器</div></a>" +
        "<a class='btn-item' href='https://www.firefox.com.cn/download/' target='_blank'>" +
        "<img src='https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/icon-firefox.svg' />" +
        "<div class='btn-text'>火狐浏览器</div></a>" +
        "</div>" +
        "<div class='btn-close'>关闭</div>" +
        "</div>";

    tips.getElementsByClassName("btn-close")[0].onclick = function () {
        document.body.removeChild(tips);
    };
    document.body.appendChild(tips);
}

window.onload = function () {
    if (isIE()) {
        // 判断ie加上弹出框
        // if (!sessionStorage.getItem("tips")) {
        showTips();
        // }
        // sessionStorage.setItem("tips", 1);

        // IE浏览器加载轮播图
        // 添加样式
        loadCss("css/ie.css");
        loadCss("css/swiper.min.css");
        loadScript("js/swiper.min.js", function () {
            new Swiper(".p-swiper", {
                autoplay: {
                    delay: 3000,
                    pauseOnMouseEnter: true,
                },
                pagination: {
                    el: ".swiper-pagination",
                    clickable: true,
                },
            });
        });

        var swiper = document.getElementsByClassName("p-swiper")[0];
        var banners = document.getElementsByClassName("banner");

        swiper.style.height =
            Math.ceil(
                (window.innerWidth / 1920) * parseInt(swiper.style.height)
            ) + "px";
        for (let i = 0; i < banners.length; i++) {
            banners[i].style.height =
                Math.ceil(
                    (window.innerWidth / 1920) *
                        parseInt(banners[i].style.height)
                ) + "px";
        }

        // 初始化轮播图高度
    }
};
